﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GeneralLibs
{
    public class License
    {
        public static bool IsValidLicence()
        {
            try
            {
                string inputSerialAndExpiryDate = LocalSettings.HeThong.SerialKey;
                string inputSerial = inputSerialAndExpiryDate.Substring(inputSerialAndExpiryDate.IndexOf("-")+1);

                string actualCpuSerial = CommonLib.MaHoaMD5(LocalSettings.HeThong.HardwareID) + "C";
                if (inputSerial == actualCpuSerial)
                {
                    return true;
                }
                else
                {
                    string actualCompanyNameSerial = CommonLib.MaHoaMD5(Config.TenDoanhNghiep) + "B";
                    if (inputSerial == actualCompanyNameSerial) 
                        return  true;
                }

                return false;
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        private static DateTime GetExpiryDate()
        {
            string inputSerialAndExpiryDate = LocalSettings.HeThong.SerialKey;
            string strExpiryDate = inputSerialAndExpiryDate.Substring(0, inputSerialAndExpiryDate.IndexOf("-"));
            return CommonLib.DecryptDateTime(strExpiryDate);
        }
        public static bool IsExpired()
        {
            try
            {
                return CommonLib.GetSystemDateTime().Date > GetExpiryDate();
            }
            catch (Exception ex)
            {
                return true;   
            }
        }
    }
}
